﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;

namespace jSLCore.Client.Presentation.Controls
{
    public partial class ImageButton : ImageButtonBase
    {
        public ImageButton()
        {
            this.DefaultStyleKey = typeof(ImageButton);

        }

        public bool FillSpace
        {
            get { return ((Image)GetTemplateChild("PART_image")).Stretch == Stretch.Fill; }
            set
            {
                try
                {
                    ((Image)GetTemplateChild("PART_image")).Stretch = value ? Stretch.Fill : Stretch.None;
                }
                catch (Exception)
                {
                    
                } 
            }
        }

        private void SetSmaller(FrameworkElement sender)
        {
            sender.RenderTransform = new ScaleTransform() { ScaleX = 1, ScaleY = 1 };
        }

        private void SetBigger(FrameworkElement sender)
        {
            var scaleTransform = new ScaleTransform() { ScaleX = 1, ScaleY = 1.06};

            sender.RenderTransformOrigin = new Point(0.5, 0.5);
            sender.RenderTransform = scaleTransform;

        }

        protected override void OnMouseEnter(MouseEventArgs e)
        {
            SetBigger((FrameworkElement) this);
        }

        protected override void OnMouseLeave(MouseEventArgs e)
        {
            SetSmaller((FrameworkElement)this);
        }
    }
}
